﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProductionLine.API.Application.Command.Car;
using ProductionLine.Domain.Car;
using ProductionLine.ErrorCode;
using ProductionLine.Extensions;

namespace ProductionLine.API.Controllers
{
    /// <summary>
    /// 车间管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class CarController : ControllerBase
    {
        IMediator mediator;
        ILogger<CarController> logger;


        public CarController(IMediator mediator, ILogger<CarController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 车间
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<CarModel>>> GetCar([FromQuery]GetCarCommand request)
        {
            logger.LogInformation("查询车间信息成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 生产线
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<ProductLineDTO>>> GetProductLine([FromQuery]GetProductLineCommand request)
        {
            logger.LogInformation("查询生产线信息成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 部门用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<UserDepartmentDTO>>> GetUserDepartment([FromQuery]GetDepartmentUserCommand request)
        {
            logger.LogInformation("查询部门用户成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 新增车间
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddCar(AddCarCommand request)
        {
            logger.LogInformation("新增车间成功");
            return await mediator.Send(request);
        }
        /// <summary>
        /// 新增生产线
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddProductLine(AddProductLineCommand request)
        {
            logger.LogInformation("新增生产线成功"); 
            return await mediator.Send(request);
        }
        /// <summary>
        /// 新增站点
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> Addsite(AddSiteCommand request)
        {
            logger.LogInformation("新增站点成功");
            return await mediator.Send(request);
        }
        /// <summary>
        /// 站点信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<SiteDTO>>> GetSite([FromQuery]GetSiteCommand request)
        {
            logger.LogInformation("查询站点成功");
            return mediator.Send(request);
        }
    }
}
